import { createRouter, createWebHistory ,createWebHashHistory} from "vue-router";
import { staticRoutes } from "@/router/routes";
import NProgress from 'nprogress';
import 'nprogress/nprogress.css'; 
import { log } from "@antv/g2plot/lib/utils";
// import {modelRoutes} from "./routesModel"
// let shouRoute=[] as any;
// function setRoutes(){
//   window.addEventListener('resize', function() {
//     // IsMobile3()
//   })
// }
// function IsMobile(){
//   if(navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)){
//     shouRoute=modelRoutes;
//   }else{
//     shouRoute=staticRoutes;
//   }
// }
// function IsMobile2(){
//   if(navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)){
//      window.location.reload()
//   }else{
//   }
// }
// function IsMobile3(){

// }


// setRoutes();


var router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes:staticRoutes ,
  // 滚动行为：当路由组件切换时滚动条的位置
  scrollBehavior() {
    return { top: 0, left: 0 };
  },
});
// 当路由开始跳转时

router.beforeEach((to, from, next) => {
  // interface MyReq {
  //   headers: { [key: string]: string; };
  //   connection: { remoteAddress: string; };
  // }

  // let req: MyReq;
  // req = router.currentRoute.value.params as unknown as MyReq
  // console.log('router.currentRoute.value',router.currentRoute.value);
  
  // const clientIP = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
  // console.log('ip',clientIP);
  
  // 开启进度条
  NProgress.start();
  next();
});

// 当路由跳转结束后
router.afterEach(() => {
  // 关闭进度条
  NProgress.done();
});
// router.beforeEach((to, from, next) => {
//   if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
//     window.location.href = '/move.html/'
//     return
//   }
//   next()
// })

// 导出路由
export default router;
